package me.caofeng.pojo;

import org.apache.logging.log4j.LogManager;

import java.util.List;

/**
 * Copyright © 2017曹峰. All rights reserved.
 *
 * @Prject: mall
 * @Package: me.caofeng.pojo
 * @Description:  购物车
 * @Author: 曹峰 blog.caofeng.me
 * @Date: 2017-06-25 18:16
 * @Version: V1.0
 */
public class Carts {
    /**
     * 购物车商品总数
     */
    private int count;

    /**
     * 购物车总价格
     */
    private int price;

    /**
     * 购物车商品信息
     */
    private List<CartItem> cartItems;

    /**
     * 选中数量
     */
    private int checkedCount;

    /**
     * 选中价格
     */
    private int checkedPrice;

    /**
     * 是否全选
     */
    private boolean allChecked;

    public Carts() {
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public List<CartItem> getCartItems() {
        return cartItems;
    }

    public void setCartItems(List<CartItem> cartItems) {
        this.cartItems = cartItems;
        if (null != cartItems && cartItems.size() > 0){
            calculatorPrice();
        }
    }

    private void calculatorPrice() {
        count = cartItems.size();
        for (CartItem cartItem : cartItems ){
            price = price + cartItem.getPrice();
            if (cartItem.getChecked().isStatus()){
                checkedCount = checkedCount + 1;
                checkedPrice = checkedPrice + cartItem.getPrice();
            }
        }

        if (checkedCount == count){
            allChecked = true;
        }
    }

    public int getCheckedCount() {
        return checkedCount;
    }

    public void setCheckedCount(int checkedCount) {
        this.checkedCount = checkedCount;
    }

    public int getCheckedPrice() {
        return checkedPrice;
    }

    public void setCheckedPrice(int checkedPrice) {
        this.checkedPrice = checkedPrice;
    }

    public boolean isAllChecked() {
        return allChecked;
    }

    public void setAllChecked(boolean allChecked) {
        this.allChecked = allChecked;
    }

    @Override
    public String toString() {
        return "Carts{" +
                "count=" + count +
                ", price=" + price +
                ", cartItems=" + cartItems +
                ", checkedCount=" + checkedCount +
                ", checkedPrice=" + checkedPrice +
                ", allChecked=" + allChecked +
                '}';
    }
}
